import 'babel-polyfill'
import Vue from 'vue'
import VueLazyload from 'vue-lazyload'
import router from './routers'
import './components'
import '../static/jquery.form.js'
import 'css/base.scss'
import './common/filters'
import store from './store'
// import { session } from 'js/util'

Vue.use(VueLazyload, {
  attempt: 1
})

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.meta.isAuth) {
    const userInfo = session.get('userInfo') || {}
    if (userInfo.accessToken) {
      next()
    } else {
      window.$toast('亲，请先登录', () => {
        next({
          path: `/login`
        })
      })
    }
  } else {
    next()
  }
})

/* eslint-disable no-new */
export default new Vue({
  el: '#app',
  router,
  store
})
